#include <avr/interrupt.h>
#include "init.h"



void timerInit(void)
{
	
	
	// set timer0 counter initial value to 0
	TCNT0=0x00;
	// start timer0 with /1024 prescaler 
	//pg 74 clear timer on compare match
	TCCR0 = (1<<CS02) | (1<<CS00) | (1<<WGM01);
	
	OCR0 = 255; //setting max value for testing
	
	// enable timer compare match interrupt
	TIMSK = (1<<OCIE0);
}


/* initialise with prescalar and precision
* enable ADC, select ADC clock = F_CPU / 8 (i.e. 125 kHz)
*/
void adcInit(void)
{
	/* 
	*	ADEN -> ADC enable
	*	ADPS01 -> prescalar F_CPU/8
	*	ADIE	-> interrupt enable
	*/
	ADCSRA = _BV(ADEN) | _BV(ADPS1) | _BV(ADPS0) | _BV(ADIE);
	
	ADCSRA |= _BV(ADSC); /* start first conversion */
	
	/*
	*	REFS1:0 = 0b11 -> Internal 2.56V Voltage Reference with external capacitor at AREF pin
	*/	
	ADMUX = _BV(REFS1) | _BV(REFS0);
}